package jface.solutions.util;

import jface.data.Person;

import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;

public class PersonLabelProviderExercise extends LabelProvider implements ITableLabelProvider {
		
	public String getText(Object element) {
		Person person = (Person) element;
		return person.getFirstName()+" "+person.getLastName()+" ("+person.getAge()+")";
	}
		
	public String getColumnText(Object element, int index) {
		Person person = (Person) element;
		switch (index) {
		case 0:
			switch (person.getGender()) {
			case male:
				return "Mr. " + person.getFirstName() + " " + person.getLastName();
			case female:
				return "Ms. " + person.getFirstName() + " " + person.getLastName();
			default:
				return person.getFirstName() + " " + person.getLastName();
			}
		case 1:
			if(person.getAge() < 10){
				return "< 10 Y";
				
			}else{
				return "> " + (person.getAge() / 10) + "0 Y";			
			}
		case 2:
			switch (person.getGender()) {
			case male:
				return "Man";
			case female:
				return "Woman";
			default:
				return "Unknown";
			}
		}
		return "?";
	}

	public Image getColumnImage(Object arg0, int arg1) {
		return null;
	}
	

}
